package com.dongpl.config.quartz.Job;

import com.dongpl.module.sysUser.entity.SysUser;
import com.dongpl.module.sysUser.service.SysUserService;
import com.dongpl.utils.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定时增加用户信息
 */
@Slf4j
public class AddUserTask extends QuartzJobBean {

    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private static final String salt = "123456";

    private static final String username = "admin";

    private static final String password = "admin";

    @Resource
    private SysUserService userService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {
        log.info("增加用户 >>> {}" + sdf.format(new Date()));
        SysUser user = new SysUser();
        double random = Math.random();
        System.out.println("random >>> " + random);
        user.setUsername(username);
        String sha256 = ShiroUtils.sha256(password, salt);
        user.setPassword(sha256);
        user.setSalt(salt);
//        userService.insertUser(user);
    }

}
